/<template>
  <div>
    <ul class="goods">
      <li v-for="item in goods" :key="item.id">
        <img :src="item.img" alt="" @click="toDetail(item.id)" />
        <div>
          <h3>{{ item.title }}</h3>
          <h3 class="text">{{ item.text }}</h3>
          <h3 class="price">￥{{ item.price }}元</h3>
          <h3>已售{{ item.num }}件</h3>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import axios from "../config/axios.js";
export default {
  data() {
    return {
      goods: [],
    };
  },
  mounted() {
    axios.get("/goodsList").then((res) => {
      console.log(res.data);
      this.goods = res.data;
    });
  },
  methods:{
      toDetail(id){
          this.$router.push({
              name:'Detail',
              params: {
                  id
              },
          })
      }
  }
};
</script>

<style lang='scss'>
.goods {
  display: flex;
  flex-wrap: wrap;
  li {
    width: 50%;
    height: 260px;
    padding: 5px;
    img{
        width: 100%;
        height: 150px;
    }
    .price{
        color: rgb(245, 33, 44);
    }
    .text{
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
    }
  }
}
</style>